package com.scl.springtalis.service.impl;

import com.scl.springtalis.mapper.DeptMapper;
import com.scl.springtalis.mapper.EmpMapper;
import com.scl.springtalis.polo.Dept;
import com.scl.springtalis.polo.Result;
import com.scl.springtalis.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
     private DeptMapper deptMapper;
    @Autowired
     private EmpMapper empMapper;



    public List<Dept> list() {
        return deptMapper.list();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void Delete(int id) {
        deptMapper.Delete(id);

        empMapper.delectById(id);

    }

    @Override
    public void Add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.Add(dept);
    }
}
